﻿angular.module('core.services', ['ngResource', 'core.filters'])
	.factory("WebApiService", ['ResourceProvider', function (ResourceProvider) {
		return {
			getSiteSettings: function (restUri, params, successFn, errorFn) {
				return ResourceProvider.doAction(restUri, params, successFn, errorFn);
			}
		};
	}])

	.factory("ResourceProvider", ['$resource', '$filter', function ($resource, $filter) {
		return {
			getResource: function(restUri, actions) {
				var verb = $filter('getVerb')(restUri);
				var url = $filter('stripVerb')(restUri);
				var action = {
					method: verb
					//Note: setting the responseType causes safari to explode
					//responseType: 'json'
				};
				angular.extend(action, actions);
				return $resource(url, {}, { doAction: action });
			},
			doAction: function(restUri, params, successFn, errorFn) {
				var resource = this.getResource(restUri);
				return resource.doAction(params, successFn, errorFn);
			}
		};
	}])